package com.logistics.modules.sys.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.logistics.common.utils.DataDictionaryConstantClass;
import com.logistics.modules.transportationManagement.entity.MoveplanEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.logistics.common.utils.PageUtils;
import com.logistics.common.utils.Query;

import com.logistics.modules.sys.dao.SystemcodetableDao;
import com.logistics.modules.sys.entity.SystemcodetableEntity;
import com.logistics.modules.sys.service.SystemcodetableService;


@Service("systemcodetableService")
public class SystemcodetableServiceImpl extends ServiceImpl<SystemcodetableDao, SystemcodetableEntity> implements SystemcodetableService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SystemcodetableEntity> page = new Query<SystemcodetableEntity>().getPage(params);
        this.baseMapper.queryPage(page, Convert.toStr(params.get("classificationid")));
        return new PageUtils(page);
    }

    /**
     * 根据客户订单状态得到集合
     *
     * @return {@link List}<{@link SystemcodetableEntity}>
     */
    @Override
    public List<SystemcodetableEntity> getListByCliOrder() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.CUSTOMERORDERSTATUS);
    }

    /**
     * 根据客货物单位得到集合
     *
     * @return {@link List}<{@link SystemcodetableEntity}>
     */
    @Override
    public List<SystemcodetableEntity> getListByCargoUnit() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.CARGOUNIT);
    }

    /**
     * 根据物流位置得到集合
     *
     * @return {@link List}<{@link SystemcodetableEntity}>
     */
    @Override
    public List<SystemcodetableEntity> getListByLogisticsLocation() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.LOGISTICS_LOCATION);
    }

    @Override
    public List<SystemcodetableEntity> getListByPlanMoney() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.PLAN_MONEY);
    }

    @Override
    public List<SystemcodetableEntity> getListByPlanStatus() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.PLAN_STATUS);
    }

    @Override
    public List<SystemcodetableEntity> getListByPlanCargoStatus() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.PLAN_CARGO_STATUS);
    }

    @Override
    public List<SystemcodetableEntity> getListByVehicleShippingOrderStatus() {
        return this.baseMapper.selectAllByClassificationid(DataDictionaryConstantClass.VEHICLE_SHIPPING_ORDER_STATUS);
    }

    /**
     * 得到逾期费用
     *
     * @return {@link Double}
     * @param moveplanEntity
     */
    @Override
    public Double getOverdueFees(MoveplanEntity moveplanEntity) {
        // 获取系统代码实体类
        SystemcodetableEntity systemCode = this.baseMapper.selectOneByClassificationidAndItemCode(DataDictionaryConstantClass.WAREHOUSE_STORAGE_COST, 0);
        // 返回
        Double percentage = Convert.toDouble(systemCode.getContent());
        // 效验
        if (percentage == null) {
            throw new RuntimeException("仓库保存的费用百分比获取异常! 请检查系统系统代码!");
        }
        // 计算逾期费用
        Double money = moveplanEntity.getFreight().getCargoMoeny() * percentage;

        return money;
    }

    /**
     * 得到默认节省时间
     *
     * @return {@link Integer}
     */
    @Override
    public Integer getDefaultSaveTime() {
        // 获取系统代码实体类
        SystemcodetableEntity systemCode = this.baseMapper.selectOneByClassificationidAndItemCode(DataDictionaryConstantClass.REPOSITORY_DEFAULT_SAVE_DAY, 0);
        // 返回
        return Convert.toInt(systemCode.getContent());
    }

}